﻿using System;
using System.Runtime.InteropServices;
using System.Security;

namespace Tnelab.Common
{
    using IntPtr = IntPtr;
    [SuppressUnmanagedCodeSecurity]
    public static class Win32Api
    {
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct BROWSEINFO
        {
            public IntPtr hwndOwner;
            public IntPtr pidlRoot;
            public IntPtr pszDisplayName;
            public string lpszTitle;
            public UInt32 ulFlags;
            public IntPtr lpfn;
            public UInt32 lParam;
            public int iImage;
        }
        [UnmanagedFunctionPointer(CallingConvention.Winapi, SetLastError = true)]
        public delegate int WinProcDelegate(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam);
        [UnmanagedFunctionPointer(CallingConvention.Winapi, SetLastError = true)]
        public delegate IntPtr LPOFNHOOKPROC(IntPtr Arg1, UInt32 Arg2, UInt32 Arg3, UInt32 Arg4);
        public enum HitTest : int                   //测试句柄
        {
            #region 测试句柄

            HTERROR = -2,
            HTTRANSPARENT = -1,
            HTNOWHERE = 0,
            HTCLIENT = 1,
            HTCAPTION = 2,
            HTSYSMENU = 3,
            HTGROWBOX = 4,
            HTSIZE = HTGROWBOX,
            HTMENU = 5,
            HTHSCROLL = 6,
            HTVSCROLL = 7,
            HTMINBUTTON = 8,
            HTMAXBUTTON = 9,
            HTLEFT = 10,
            HTRIGHT = 11,
            HTTOP = 12,
            HTTOPLEFT = 13,
            HTTOPRIGHT = 14,
            HTBOTTOM = 15,
            HTBOTTOMLEFT = 16,
            HTBOTTOMRIGHT = 17,
            HTBORDER = 18,
            HTREDUCE = HTMINBUTTON,
            HTZOOM = HTMAXBUTTON,
            HTSIZEFIRST = HTLEFT,
            HTSIZELAST = HTBOTTOMRIGHT,
            HTOBJECT = 19,
            HTCLOSE = 20,
            HTHELP = 21

            #endregion
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct OPENFILENAMEW
        {
            public Int32 lStructSize;
            public IntPtr hwndOwner;
            public IntPtr hInstance;
            public string lpstrFilter;
            public string lpstrCustomFilter;
            public Int32 nMaxCustFilter;
            public Int32 nFilterIndex;
            public IntPtr lpstrFile;
            public Int32 nMaxFile;
            public string lpstrFileTitle;
            public Int32 nMaxFileTitle;
            public string lpstrInitialDir;
            public string lpstrTitle;
            public Int32 Flags;
            public Int16 nFileOffset;
            public Int16 nFileExtension;
            public string lpstrDefExt;
            public UInt32 lCustData;
            public LPOFNHOOKPROC lpfnHook;
            public string lpTemplateName;
            public IntPtr pvReserved;
            public Int32 dwReserved;
            public Int32 FlagsEx;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct NOTIFYICONDATA
        {
            public int cbSize;
            public IntPtr hWnd;
            public int uID;
            public int uFlags;
            public int uCallbackMessage;
            public IntPtr hIcon;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
            public string szTip;
            public int dwState;
            public int dwStateMask;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x100)]
            public string szInfo;
            public int uTimeoutOrVersion;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x40)]
            public string szInfoTitle;
            public int dwInfoFlags;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct WNDCLASS
        {
            public uint style;
            public IntPtr lpfnWndProc;
            public int cbClsExtra;
            public int cbWndExtra;
            public IntPtr hInstance;
            public IntPtr hIcon;
            public IntPtr hCursor;
            public IntPtr hbrBackground;
            public IntPtr lpszMenuName;
            public string lpszClassName;
        }
        [StructLayout(LayoutKind.Sequential)]
        public unsafe class UPDATELAYEREDWINDOWINFO
        {
            public Int32 cbSize;
            public IntPtr hdcDst;
            public POINT* pptDst;
            public SIZE* psize;
            public IntPtr hdcSrc;
            public POINT* pptSrc;
            public Int32 crKey;
            public BLENDFUNCTION* pblend;
            public Int32 dwFlags;
            public RECT* prcDirty;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct POINT
        {
            public Int32 x;
            public Int32 y;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        public struct MSG
        {
            public IntPtr hwnd;
            public UInt32 message;
            public UInt32 wParam;
            public UInt32 lParam;
            public Int32 time;
            public POINT pt;
            public Int32 lPrivate;
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct RECT
        {
            public Int32 left;
            public Int32 top;
            public Int32 right;
            public Int32 bottom;
        }

        #region Nested type: MINMAXINFO
        [StructLayout(LayoutKind.Sequential)]
        public struct MINMAXINFO
        {
            public POINT ptReserved;
            public POINT ptMaxSize;
            public POINT ptMaxPosition;
            public POINT ptMinTrackSize;
            public POINT ptMaxTrackSize;
        }
        #endregion

        #region Nested type: MONITORINFO
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class MONITORINFO
        {
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
            public RECT rcMonitor;
            public RECT rcWork;
            public int dwFlags;
        }
        #endregion
        [StructLayout(LayoutKind.Sequential)]
        public struct SIZE
        {
            public Int32 cx;
            public Int32 cy;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct BLENDFUNCTION
        {
            public byte BlendOp;
            public byte BlendFlags;
            public byte SourceConstantAlpha;
            public byte AlphaFormat;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct COMPOSITIONFORM
        {
            public int dwStyle;
            public POINT ptCurrentPos;
            public RECT rcArea;
        }
        public const Int32 ULW_COLORKEY = 0x00000001;
        public const Int32 ULW_ALPHA = 0x00000002;
        public const Int32 ULW_OPAQUE = 0x00000004;

        public const byte AC_SRC_OVER = 0x00;
        public const byte AC_SRC_ALPHA = 0x01;

        public const byte CFS_DEFAULT = 0x0;
        public const byte CFS_RECT = 0x1;
        public const byte CFS_POINT = 0x2;
        public const byte CFS_SCREEN = 0x4;
        public const byte CFS_FORCE_POSITION = 0x20;
        public const byte CFS_CANDIDATEPOS = 0x40;
        public const byte CFS_EXCLUDE = 0x80;

        public const int GWL_STYLE = (-16);
        public const int GWL_EXSTYLE = (-20);
        public const int LWA_ALPHA = 0;

        public const int CS_VREDRAW = 0x0001;
        public const int CS_HREDRAW = 0x0002;
        public const int CS_DBLCLKS = 0x0008;
        public const int CS_OWNDC = 0x0020;
        public const int CS_CLASSDC = 0x0040;
        public const int CS_PARENTDC = 0x0080;
        public const int CS_NOCLOSE = 0x0200;
        public const int CS_SAVEBITS = 0x0800;
        public const int CS_BYTEALIGNCLIENT = 0x1000;
        public const int CS_BYTEALIGNWINDOW = 0x2000;
        public const int CS_GLOBALCLASS = 0x4000;

        public const int WS_OVERLAPPED = 0x000000;
        public const int WS_POPUP = unchecked((int)0x80000000);
        public const int WS_CHILD = 0x400000;
        public const int WS_MINIMIZE = 0x200000;
        public const int WS_VISIBLE = 0x100000;
        public const int WS_DISABLED = 0x080000;
        public const int WS_CLIPSIBLINGS = 0x040000;
        public const int WS_CLIPCHILDREN = 0x020000;
        public const int WS_MAXIMIZE = 0x010000;
        public const int WS_CAPTION = 0x00C000;     /* WS_BORDER | WS_DLGFRAME  */
        public const int WS_BORDER = 0x008000;
        public const int WS_DLGFRAME = 0x004000;
        public const int WS_VSCROLL = 0x002000;
        public const int WS_HSCROLL = 0x001000;
        public const int WS_SYSMENU = 0x000800;
        public const int WS_THICKFRAME = 0x000400;
        public const int WS_GROUP = 0x000200;
        public const int WS_TABSTOP = 0x000100;

        public const int WS_MINIMIZEBOX = 0x000200;
        public const int WS_MAXIMIZEBOX = 0x000100;
        public const int WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);

        public const int WS_EX_LAYERED = 0x00080000;
        public const int WS_EX_TRANSPARENT = 0x20;
        public const int WS_EX_APPWINDOW = 0x00040000;
        public const int WS_EX_TOOLWINDOW = 0x00000080;


        /*
         * ShowWindow() Commands
        */
        public const int SW_HIDE = 0;
        public const int SW_SHOWNORMAL = 1;
        public const int SW_NORMAL = 1;
        public const int SW_SHOWMINIMIZED = 2;
        public const int SW_SHOWMAXIMIZED = 3;
        public const int SW_MAXIMIZE = 3;
        public const int SW_SHOWNOACTIVATE = 4;
        public const int SW_SHOW = 5;
        public const int SW_MINIMIZE = 6;
        public const int SW_SHOWMINNOACTIVE = 7;
        public const int SW_SHOWNA = 8;
        public const int SW_RESTORE = 9;
        public const int SW_SHOWDEFAULT = 10;
        public const int SW_FORCEMINIMIZE = 11;
        public const int SW_MAX = 11;

        public const int SM_CXSCREEN = 0;
        public const int SM_CYSCREEN = 1;

        /*
        * Window Messages
        */
        public const uint WM_USER = 0x0400;
        public const uint WM_UI_INVOKE = WM_USER + 1;
        public const uint WM_NULL = 0x0000;
        public const uint WM_CREATE = 0x0001;
        public const uint WM_DESTROY = 0x0002;
        public const uint WM_MOVE = 0x0003;
        public const uint WM_SIZE = 0x0005;

        public const uint WM_ACTIVATE = 0x0006;
        public const uint WM_SHOWWINDOW = 0x0018;
        public const uint WM_CLOSE = 0x0010;
        public const uint WM_NCDESTROY = 0x0082;
        public const uint WM_GETMINMAXINFO = 0x0024;
        public const uint WM_IME_STARTCOMPOSITION = 0x010d;
        public const uint WM_MOUSEMOVE = 0x0200;
        public const uint WM_RBUTTONDOWN = 0x0204;
        public const uint WM_RBUTTONUP = 0x0205;
        public const uint WM_KEYDOWN = 0x0100;
        public const uint WM_KEYUP = 0x0101;
        public const uint WM_CHAR = 0x0102;
        public const uint WM_IME_SETCONTEXT = 0x0281;
        public const uint WM_IME_NOTIFY = 0x0282;

        public const uint WM_SETCURSOR = 0x0020;
        public const uint WM_SETFOCUS = 0x0007;
        public const uint WM_KILLFOCUS = 0x0008;

        public const uint WM_MOUSEWHEEL = 0x020a;
        public const uint WM_LBUTTONDOWN = 0x0201;
        public const uint WM_LBUTTONUP = 0x0202;
        public const uint WM_SYSCOMMAND = 0x0112;
        public const uint WM_SIZING = 0x0214;
        public const uint WM_SETTINGCHANGE = 0x001A;
        public const int WM_NCHITTEST = 0x0084;    //测试消息
        public const int WM_PAINT = 0x000F;

        public const int WM_MBUTTONDOWN = 0x0207;
        public const int WM_MBUTTONUP = 0x0208;
        public const int WM_DROPFILES = 0x0233;
        public const int WM_CONTEXTMENU = 0x007B;
        public const int WM_WM_WINDOWPOSCHANGED = 0x0047;

        public const int CW_USEDEFAULT = unchecked((int)0x80000000);

        public const int SC_MOVE = 0xF012;
        public const int SC_SIZE = 0xF000;

        public const int SC_MAXIMIZE = 61488;
        public const int SC_MINIMIZE = 61472;

        public const int SRCCOPY = 0xCC0020;
        public const int HTCAPTION = 2;   //标题栏
        public const Int32 CAPTUREBLT = 0x40000000;

        public const int KF_EXTENDED = 0x0100;
        public const int KF_DLGMODE = 0x0800;
        public const int KF_MENUMODE = 0x1000;
        public const int KF_ALTDOWN = 0x2000;
        public const int KF_REPEAT = 0x4000;
        public const int KF_UP = 0x8000;

        public const int WM_GETICON = 0x007F;
        public const int WM_SETICON = 0x0080;
        public const int ICON_SMALL = 0;
        public const int ICON_BIG = 1;


        public const int LR_DEFAULTCOLOR = 0x00000000;
        public const int LR_MONOCHROME = 0x00000001;
        public const int LR_COLOR = 0x00000002;
        public const int LR_COPYRETURNORG = 0x00000004;
        public const int LR_COPYDELETEORG = 0x00000008;
        public const int LR_LOADFROMFILE = 0x00000010;
        public const int LR_LOADTRANSPARENT = 0x00000020;
        public const int LR_DEFAULTSIZE = 0x00000040;
        public const int LR_VGACOLOR = 0x00000080;
        public const int LR_LOADMAP3DCOLORS = 0x00001000;
        public const int LR_CREATEDIBSECTION = 0x00002000;
        public const int LR_COPYFROMRESOURCE = 0x00004000;
        public const int LR_SHARED = 0x00008000;

        public const int MK_LBUTTON = 0x0001;
        public const int MK_RBUTTON = 0x0002;
        public const int MK_SHIFT = 0x0004;
        public const int MK_CONTROL = 0x0008;
        public const int MK_MBUTTON = 0x0010;
        public const int SPI_GETWORKAREA = 0x0030;

        public const int NIM_ADD = 0x00000000;
        public const int NIM_MODIFY = 0x00000001;
        public const int NIM_DELETE = 0x00000002;
        public const int NIM_SETFOCUS = 0x00000003;
        public const int NIM_SETVERSION = 0x00000004;

        public const int NIF_MESSAGE = 0x00000001;
        public const int NIF_ICON = 0x00000002;
        public const int NIF_TIP = 0x00000004;
        public const int NIF_STATE = 0x00000008;
        public const int NIF_INFO = 0x00000010;


        public enum TernaryRasterOperations : uint
        {
            /// <summary>dest = source</summary>
            SRCCOPY = 0x00CC0020,
            /// <summary>dest = source OR dest</summary>
            SRCPAINT = 0x00EE0086,
            /// <summary>dest = source AND dest</summary>
            SRCAND = 0x008800C6,
            /// <summary>dest = source XOR dest</summary>
            SRCINVERT = 0x00660046,
            /// <summary>dest = source AND (NOT dest)</summary>
            SRCERASE = 0x00440328,
            /// <summary>dest = (NOT source)</summary>
            NOTSRCCOPY = 0x00330008,
            /// <summary>dest = (NOT src) AND (NOT dest)</summary>
            NOTSRCERASE = 0x001100A6,
            /// <summary>dest = (source AND pattern)</summary>
            MERGECOPY = 0x00C000CA,
            /// <summary>dest = (NOT source) OR dest</summary>
            MERGEPAINT = 0x00BB0226,
            /// <summary>dest = pattern</summary>
            PATCOPY = 0x00F00021,
            /// <summary>dest = DPSnoo</summary>
            PATPAINT = 0x00FB0A09,
            /// <summary>dest = pattern XOR dest</summary>
            PATINVERT = 0x005A0049,
            /// <summary>dest = (NOT dest)</summary>
            DSTINVERT = 0x00550009,
            /// <summary>dest = BLACK</summary>
            BLACKNESS = 0x00000042,
            /// <summary>dest = WHITE</summary>
            WHITENESS = 0x00FF0062,
            /// <summary>
            /// Capture window as seen on screen.  This includes layered windows
            /// such as WPF windows with AllowsTransparency="true"
            /// </summary>
            CAPTUREBLT = 0x40000000
        }


        [DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
        public static extern Int32 GetLastError();
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
        public static extern IntPtr RegisterClassW(ref WNDCLASS Arg1);
        [DllImport("user32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
        public static extern IntPtr CreateWindowExW(
            Int32 dwExStyle,
            string lpClassName,
            string lpWindowName,
            Int32 dwStyle,
            Int32 x,
            Int32 y,
            Int32 nWidth,
            Int32 nHeight,
            IntPtr hWndParent,
            IntPtr hMenu,
            IntPtr hInstance,
            IntPtr lpParam
        );
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return:MarshalAs(UnmanagedType.Bool)]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetMessage(ref MSG lpMsg, IntPtr hWnd, UInt32 wMsgFilterMin, UInt32 wMsgFilterMax);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool TranslateMessage(ref MSG lpMsg);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern Int32 DispatchMessage(ref MSG lpMsg);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern Int32 DefWindowProc(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern void PostQuitMessage(int nExitCode);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern int GetSystemMetrics(int nIndex);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, [MarshalAs(UnmanagedType.Bool)]bool bRepaint);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, UInt32 uFlags);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr GetParent(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool CloseWindow(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnableWindow(IntPtr hWnd, [MarshalAs(UnmanagedType.Bool)]bool bEnable);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr SetActiveWindow(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool DestroyWindow(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi,SetLastError =true)]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
        [DllImport("User32", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern int ReleaseCapture();
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UpdateLayeredWindow(IntPtr hWnd, IntPtr hdcDst,ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc,ref POINT pptSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UpdateLayeredWindowIndirect(IntPtr hwnd, UPDATELAYEREDWINDOWINFO pULWInfo);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr GetDC(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UpdateWindow(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool IsZoomed(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr SetCursor(IntPtr hCursor);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern IntPtr LoadCursorA(IntPtr hInstance, int lpCursorName);
        [DllImport("Gdi32.dll", CallingConvention = CallingConvention.Winapi)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool BitBlt(IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, Int32 rop);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi)]
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string lpString);
        [DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi)]
        public static extern IntPtr LoadLibraryA(string lpLibFileName);
        [DllImport("Kernel32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
        public static extern IntPtr LoadLibraryW(string lpLibFileName);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern IntPtr CreateIconFromResourceEx(
          IntPtr presbits,
          Int32 dwResSize,
          int fIcon,
          Int32 dwVer,
          int cxDesired,
          int cyDesired,
          UInt32 Flags
        );
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern IntPtr CreateIconFromResource(
          IntPtr presbits,
          int dwResSize,
          [MarshalAs(UnmanagedType.Bool)]
          bool fIcon,
          int dwVer
        );
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern IntPtr SetFocus(IntPtr hWnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern IntPtr SetCapture(IntPtr hwnd);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetCursorPos(ref POINT lpPoint);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool PtInRect(ref RECT lprc, POINT pt);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern IntPtr LoadCursorW(IntPtr hInstance, uint lpCursorName);
        [DllImport("user32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern void DragAcceptFiles(IntPtr hWnd, [MarshalAs(UnmanagedType.Bool)]bool fAccept);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern void DragFinish(IntPtr hDrop);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern UInt32 DragQueryFileW(IntPtr hDrop, UInt32 iFile, IntPtr lpszFile, UInt32 cch);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool DragQueryPoint(IntPtr hDrop, ref POINT ppt);
        [DllImport("User32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SystemParametersInfoW(UInt32 uiAction, UInt32 uiParam, IntPtr pvParam, UInt32 fWinIni);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool Shell_NotifyIcon(Int32 dwMessage, IntPtr lpdata);
        [DllImport("User32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
        public static extern IntPtr GetForegroundWindow();
        [DllImport("Comdlg32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetOpenFileNameW(ref OPENFILENAMEW Arg1);
        [DllImport("Comdlg32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetSaveFileNameW(ref OPENFILENAMEW Arg1);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SHGetPathFromIDListW(IntPtr pidl, IntPtr pszPath);
        [DllImport("Shell32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern IntPtr SHBrowseForFolderW(ref BROWSEINFO lpbi);

        public static ushort LOWORD(IntPtr value)
        {
            return (ushort)(value.ToInt64() & 0xFFFF);
        }
        public static ushort HIWORD(IntPtr value)
        {
            return (ushort)(value.ToInt64() >> 16);
        }
        public static byte LOWBYTE(ushort value)
        {
            return (byte)(value & 0xFF);
        }
        public static byte HIGHBYTE(ushort value)
        {
            return (byte)(value >> 8);
        }
        [DllImport("gdi32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]

        public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

        [DllImport("GDI32.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true, CharSet = CharSet.Unicode)]

        public static extern bool DeleteObject(IntPtr objectHandle);
        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]

        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]

        public static extern bool DeleteDC(IntPtr hdc);
        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr GetDesktopWindow();
        [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
        public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
        [DllImport("gdi32.dll")]
        [return:MarshalAs(UnmanagedType.Bool)]
        public static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest,int nWidthDest, int nHeightDest,IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,TernaryRasterOperations dwRop);
    }
}
